var a = require("../../../@babel/runtime/helpers/defineProperty"), t = getApp();

Page({
    data: {
        activeName: 0,
        types: "activity",
        dataList: [],
        titleArr: [ "全部", "未开始", "活动中", "已结束" ],
        isLoadMore: !0
    },
    onLoad: function(a) {
        a.tag && "my" == a.tag && this.setData({
            titleArr: [ "全部", "进行中", "已中奖", "收藏", "评论" ],
            types: "my"
        }), this.setNewArr();
    },
    setNewArr: function() {
        var a = [];
        this.data.titleArr.forEach(function(t, e) {
            a.push({
                isLoadMore: !0,
                page: 1,
                total_page: 0,
                list: []
            });
        }), this.setData({
            dataList: a
        }), this.options.index && this.setData({
            activeName: Number(this.options.index)
        }), this.handleClick();
    },
    handleClick: function(e) {
        e && (this.data.activeName = e.detail.name);
        var i = this;
        if (this.data.dataList[i.data.activeName].list.length > 0) this.setData({
            isLoadMore: this.data.dataList[i.data.activeName].isLoadMore
        }); else {
            wx.showLoading({
                title: "加载中"
            });
            var s = "", d = {};
            "activity" == this.data.types ? (s = "plugin.luck-draw.frontend.index.index", d = {
                page: 1,
                search: {
                    state: this.data.activeName - 1
                }
            }, this.options.gid && (d.search.goods_id = this.options.gid)) : (s = "plugin.luck-draw.frontend.index.myLuck", 
            d = {
                page: 1,
                state: this.data.activeName
            });
            var o = t.getNetAddresss(s);
            t._postNetWork({
                url: o,
                data: d,
                success: function(t) {
                    wx.hideLoading();
                    var e, s = t.data;
                    1 == s.result ? i.setData((a(e = {}, "dataList[" + i.data.activeName + "].isLoadMore", !0), 
                    a(e, "dataList[" + i.data.activeName + "].total_page", s.data.last_page), a(e, "dataList[" + i.data.activeName + "].list", s.data.data), 
                    e)) : wx.showToast({
                        title: s.msg,
                        duration: 1e3,
                        icon: "none"
                    });
                },
                fail: function(a) {
                    wx.hideLoading(), console.log(a.msg);
                }
            });
        }
    },
    _getMoreData: function() {
        var e = this;
        if (this.setData(a({}, "dataList[" + e.data.activeName + "].isLoadMore", !1)), !(this.data.dataList[this.data.activeName].page >= this.data.dataList[this.data.activeName].total_page)) {
            "activity" == this.data.types ? (_url = "plugin.luck-draw.frontend.index.index", 
            _json = {
                search: {
                    state: this.data.activeName - 1
                }
            }, this.options.gid && (_json.search.goods_id = this.options.gid)) : (_url = "plugin.luck-draw.frontend.index.myLuck", 
            _json = {
                state: this.data.activeName
            }), this.data.dataList[this.data.activeName].page = this.data.dataList[this.data.activeName].page + 1;
            var i = t.getNetAddresss(_url);
            i += "&page=" + this.data.dataList[this.data.activeName].page, t._getNetWork({
                url: i,
                data: _json,
                success: function(t) {
                    var i = t.data;
                    if (1 == i.result) {
                        var s, d = i.data;
                        e.setData((a(s = {}, "dataList[" + e.data.activeName + "].isLoadMore", !0), a(s, "dataList[" + e.data.activeName + "].list", e.data.dataList[e.data.activeName].list.concat(d.data)), 
                        s));
                    } else {
                        var o;
                        e.setData((a(o = {}, "dataList[" + e.data.activeName + "].isLoadMore", !1), a(o, "dataList[" + e.data.activeName + "].page", e.data.dataList[e.data.activeName].page - 1), 
                        o));
                    }
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    },
    gotoIndex: function(a) {
        var t = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageH/newDraw/newDrawIndex/newDrawIndex?id=" + t
        });
    },
    gotoDetail: function(a) {
        var t = a.currentTarget.dataset.order;
        wx.navigateTo({
            url: "/packageA/member/orderdetail/orderdetail?order_id=" + t + "&orderType=luck-draw"
        });
    },
    gotoMydraw: function() {
        wx.navigateTo({
            url: "/packageH/newDraw/mydraw/mydraw"
        });
    },
    confirmSelectAddress: function() {},
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {}
});